package com.example.widget.view

import android.os.Bundle
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.res.loadImageResource
import androidx.compose.ui.unit.dp
import com.example.base.BaseActivity
import com.example.base.commonView.CommonText
import com.example.base.commonView.CommonThemeNew
import com.example.base.commonView.TitleBar
import com.example.widget.R

class ImageActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            showView()
        }
    }

    @Composable
    fun showView() {
        val context = ContextAmbient.current as ImageActivity
        val image01 = loadImageResource(id = R.mipmap.image_motorbike)
        CommonThemeNew {
            TitleBar(title = "Image") {
                context.finish()
            }
            Column(modifier = Modifier.fillMaxSize().padding(20.dp)) {
                CommonText(
                    text = "展示图片，并设置圆角",
                    modifier = Modifier.padding(0.dp, 10.dp, 0.dp, 10.dp)
                )
                image01.resource.resource?.let {
                    Image(
                        asset = it,
                        modifier = Modifier.clip(RoundedCornerShape(10.dp)).width(100.dp)
                            .height(100.dp)
                    )
                }

                CommonText(
                    text = "Glide展示网络图片",
                    modifier = Modifier.padding(0.dp, 10.dp, 0.dp, 10.dp)
                )
            }
        }
    }
}